$.fn.extend({
    lazyloadFn(){
        let t
        // $(window).on('scroll',function(){
            //防抖节流
            if(t) clearTimeout(t)
            t = setTimeout(() =>{
                //获取网页可见内容高度
                let viewHeight = (window.innerHeight || document.documentElement.clientHeight) +
                (document.body.sccrollTop || document.documentElement.scrollTop)
                // let viewHeight =( $(window).height() || $(document).height()) +($(document).scrollTop())
                
                //遍历
                this.each((index,item) =>{
                    let imgNowHeight = $(item).offset().top
                    if(viewHeight >= imgNowHeight){
                        let data = $(item).attr('data-src')
                        $(item).attr('src',data)
                    }
                })
            },1000)
        // })
        window.onscroll = () => this.lazyloadFn()

    }
    
})